//
//  IdCardInfoRectUtil.m
//  YHOCR
//
//  Created by 杨杨子 on 2018/7/24.
//  Copyright © 2018年 杨杨子. All rights reserved.
//

#import "IdCardInfoRectUtil.h"
@implementation NameRect
-(instancetype)initWithLeft:(CGFloat)left top:(CGFloat)top right:(CGFloat)right bottom:(CGFloat)bottom name:(NSString *)name{
    if (self) {
        self = [super init];
        self.left = left;
        self.top = top;
        self.right = right;
        self.bottom = bottom;
        self.name = name;
    }
    return self;
}
//-(CGFloat)width{
//    return self.right - self.left;
//}
//-(CGFloat)height{
//    return self.bottom - self.top;
//}
@end

@implementation IdCardInfoRectUtil
/**
 * 根据比例缩放位置信息
 */
-(NSArray <NameRect *>*)scaleAllRect:(NSArray <NameRect *>*)rectList AndScale:(float)scale{
    NSMutableArray <NameRect *>*newList = [NSMutableArray array];
    for (NameRect *rect in rectList) {
        NameRect *newRect = [NameRect new];
        newRect.name = rect.name;
        newRect.left = (CGFloat)rect.left *scale;
        newRect.top = (CGFloat)rect.top*scale;
        newRect.right = (CGFloat)rect.right*scale;
        newRect.bottom = (CGFloat)rect.bottom*scale;
        [newList addObject:newRect];
    }

    return newList;
}
/**
 * 获取正面标准位置信息
 */
-(NSArray <NameRect *>*)getFrontStandardRectList{
    NSMutableArray <NameRect*>*list = [NSMutableArray array];
    NameRect *name = [[NameRect alloc] initWithLeft:280 top:100 right:580 bottom:220 name:@"name"];
    NameRect *sex = [[NameRect alloc] initWithLeft:290 top:250 right:400 bottom:340 name:@"sex"];
    NameRect *min = [[NameRect alloc] initWithLeft:625 top:245 right:985 bottom:345 name:@"min"];
    NameRect *b1 = [[NameRect alloc] initWithLeft:280 top:370 right:460 bottom:470 name:@"b1"];
    NameRect *b2 = [[NameRect alloc] initWithLeft:545 top:370 right:630 bottom:470 name:@"b2"];
    NameRect *b3 = [[NameRect alloc] initWithLeft:690 top:370 right:780 bottom:470 name:@"b3"];
    NameRect *loc = [[NameRect alloc] initWithLeft:280 top:495 right:985 bottom:765 name:@"loc"];
    NameRect *num = [[NameRect alloc] initWithLeft:530 top:810 right:1480 bottom:930 name:@"num"];
    [list addObject:name];
    [list addObject:sex];
    [list addObject:min];
    [list addObject:b1];
    [list addObject:b2];
    [list addObject:b3];
    [list addObject:loc];
    [list addObject:num];
    return list;
}
/**
 * 根据提供的rect尺寸获取对应的缩放后的信息位置
 */
-(NSArray <NameRect *>*)getFrontScaleRectList:(CGRect)rect{
    float i = rect.size.width / 1600.0;
    return [self scaleAllRect:[self getFrontStandardRectList] AndScale:i];
}

@end
